package com.chazz.dao.impl;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.chazz.dao.PriceDao;
import java.sql.SQLException;
import java.util.List;

/**
 * 描述:通过商品id查询商品价格的dao层的实现
 * @author Chazz
 * @create 2020-09-23 17:40
 */
public class PriceDaoImpl implements PriceDao {

    /**
     * description: selectPrice 通过商品的id查询它的价格 <br>
     * version: 1.0 <br>
     * date: 2020/9/23 19:11 <br>
     * author: Chazz <br>
     * @param goodsId 商品id
     * @return java.lang.Double 浮点型价格
     */
    @Override
    public Double selectPrice(Integer goodsId) {
        Double d=null;
        String obj = null;
        try {
             List<Entity> goodsSku = Db.use().query("select * from sku where goodsid = ?", goodsId);
             obj = (String) goodsSku.get(0).get("price");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        d = Double.valueOf(obj);
        return d;
    }

    /**
     * description: selectCategoryId 通过商品id查询类别id<br>
     * version: 1.0 <br>
     * date: 2020/9/24 22:18 <br>
     * author: Chazz <br>
     * @param goodsId
     * @return java.lang.Integer
     */
    @Override
    public Integer selectCategoryId(Integer goodsId) {
        Integer categoryId = null;
        try {
            List<Entity> list = Db.use().query("select * from goods where goodsid = ?", goodsId);
            categoryId = (Integer) list.get(0).get("categoryId");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return categoryId;
    }
}
